<template>
	<view class="tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed customBack :bottomShadow="false" backgroundColor="#FFFFFF">
			<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
				<text class='icon tn-icon-left-arrow'></text>
			</view>
			<view class="tn-flex tn-flex-col-center tn-flex-row-center ">
				<text class="tn-text-bold tn-text-xl tn-color-black">积分明细</text>
			</view>
		</tn-nav-bar>


		<view class="" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<view v-if="integral.length>0" class="tn-padding-bottom-lg">
				<view class="tn-flex tn-flex-row-between tn-strip-bottom-min tn-padding"
					v-for="(item,index) in integral" :key="index">
					<view class="justify-content-item">
						<view class="tn-color-gray--dark tn-text-lg">
							{{item.reason}}
						</view>
						<view class="tn-color-gray tn-padding-top-xs">
							{{item.createDate}}
						</view>
					</view>
					<view class="justify-content-item tn-text-xl tn-padding-top">
						<view :class="'tn-color-' + item.color"> {{item.scoreValue}} </view>
					</view>
				</view>

				<tn-load-more :status="loadStatus"></tn-load-more>
			</view>

			<view v-else style="margin-top: 40%">
				<tn-empty :textSize="30" :iconSize="160" mode="data" text="暂无积分变更记录哦"></tn-empty>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		getHistoryList
	} from "@/api/score.js"
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	export default {
		name: 'TemplateIntegral',
		mixins: [template_page_mixin],
		data() {
			return {
				loadStatus: 'loadmore',
				historyReqParam: {
					page: 1,
					limit: 20
				},
				integral: [],
			}
		},
		created() {
			this.getHistoryListData()
		},
		onReachBottom() {
			if (this.loadStatus === 'nomore') {
				return
			}
			this.historyReqParam.page++
			this.getHistoryListData()
		},
		methods: {
			getHistoryListData() {
				getHistoryList(this.historyReqParam).then(res => {
					let data = res.data.list
					if (data.length < this.historyReqParam.limit) {
						this.loadStatus = 'nomore'
					}
					data.forEach(item => {
						if (item.scoreType === 1) {
							item.color = 'blue'
							item.scoreValue = '+' + item.scoreValue
						} else {
							item.color = 'orange'
							item.scoreValue = '-' + item.scoreValue
						}
					})
					this.integral = [...this.integral, ...data]
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 60%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

	}

	/* 间隔线 start*/
	.tn-strip-bottom-min {
		width: 100%;
		border-bottom: 1rpx solid #F8F9FB;
	}

	.tn-strip-bottom {
		width: 100%;
		border-bottom: 20rpx solid rgba(241, 241, 241, 0.8);
	}

	/* 间隔线 end*/
</style>